<?php
/**
 * Created by PhpStorm.
 * User: woody
 * Date: 17-2-16
 * Time: 下午10:46
 */

namespace App\Http\Controllers\Api;

use App\Models\Newsapi;
use Illuminate\Http\Request;

class NewsController extends ApiController {

    public function __construct()
    {
        parent::__construct();
        $this->_response['_active']['_model']       = 'News';
        $this->_response['_active']['_action']      = '';
        $this->_response['_title']                  = '小一农货-新闻案例管理';
    }
    public function index(){

        $this->_response['_active']['_action']      = 'list';

        $newsModel = new Newsapi();

        $data = $newsModel->getData();
        if(!empty($data)){
            $this->_response['news'] = $data;
            return response()->json(['code' => 0, 'msg' => '返回成功','data'=>$this->_response]);
        }else{
            return response()->json(['code' => -1, 'msg' => '返回失败']);
        }
    }

    //具体新闻 传入： id 返回
    public function getdata($id){

        $NewsModel = new Newsapi();
        $data= $NewsModel->getData($id);
        $this->_response['news'] = $data;
        if(!empty($data)){
            return response()->json(['code' => 0, 'msg' => '返回成功','data'=>$this->_response['news']]);

        }else{
            return response()->json(['code' => -1, 'msg' => '返回失败']);
        }
    }



}